package com.example.app.callback;

import lombok.extern.slf4j.Slf4j;

/**
 * @author wangzhuangzhuang
 * @DESC:
 * @date 2022-02-11 13:47
 */
@Slf4j
public class Worker {

	public void doWork() {
		MyFetcher myFetcher = new MyFetcher(new Data(1, 0));
		myFetcher.fetchData(new FetcherCallback() {

			@Override
			public void onData(Data data) throws Exception {
				log.info("Data received: {}", data);
			}

			@Override
			public void onError(Throwable cause) {
				log.error("=================An error causes=================: {}", cause.getMessage());
			}
		});
	}

	public static void main(String[] args) {
		Worker worker = new Worker();
		worker.doWork();
	}

	/**
	 * Fetcher.fetchData()方法传递一个FetcherCallback类型的参数，当获得数据或发生错误时被回调
	 *  FetcherCallback.onData()，将接收数据时被调用
	 *  FetcherCallback.onData()，将接收数据时被调用
	 * */

}